package com.kun.base.shiro;

import com.kun.base.redis.RedisUtil;
import com.kun.base.shiro.service.SSOService;
import org.apache.shiro.web.filter.authc.LogoutFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by admin on 2017/8/9.
 */
public class ShiroLogoutFilter extends LogoutFilter {

    @Override
    protected boolean preHandle(ServletRequest request, ServletResponse response) throws Exception {
        //在退出之前清除redis中的权限信息
        RedisUtil.clearUserInfo(((HttpServletRequest)request).getSession());
        //移除用户在线列表
        new SSOService().onlineUserRemove(((HttpServletRequest)request).getSession());
        //退出登录
        return super.preHandle(request, response);
    }
}
